package cn.zhaoyuening.schoolmates.web.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.zhaoyuening.schoolmates.domain.Article;
import cn.zhaoyuening.schoolmates.service.ArticleService;

@RestController
@RequestMapping(value = "admin")
public class AdminArticleController {
	@Autowired
	private ArticleService articleService;
	@RequestMapping(value="article",method=RequestMethod.POST)
	public String addArticle(@ModelAttribute Article article){
		articleService.addOrEdit(article);
		return "success";
	}
	@RequestMapping(value="article",method=RequestMethod.PUT)
	public String updateArticle(@ModelAttribute Article article){
		articleService.addOrEdit(article);
		return "success";
	}
	@RequestMapping(value="article",method=RequestMethod.DELETE)
	public String deleteArticle(Long id){
		if(id==null){
			return "fail";
		}
		Article article = new Article();
		article.setId(id);
		articleService.delete(article);
		return "success";
	}
	@RequestMapping(value="article/order",method=RequestMethod.PUT)
	public String updateOrder(Long id,Integer order){
		articleService.updateOrder(id, order);
		return "success";
	}
}
